﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dominio;
using FluentNHibernate.Mapping;
using FluentNHibernate;

namespace Infra.NHibernateFramework {
    public class ContaMap : ClassMap<Conta>{
        public ContaMap() {
            Id(x => x.Id, "IdConta").GeneratedBy.Identity();

            Map(x => x.Nome)
                .Length(100)
                .Not.Nullable();

            References(x => x.Usuario, "IdUsuario")
                .Not.Nullable();

            HasMany<Lancamento>(Reveal.Member<Conta>("_Lancamentos"))
                .KeyColumn("IdConta")
                .Inverse()
                .Cascade.AllDeleteOrphan()
                .LazyLoad()
                .AsBag();

            HasMany<Contrato>(Reveal.Member<Conta>("_Contratos"))
                .KeyColumn("IdConta")
                .Inverse()
                .Cascade.AllDeleteOrphan()
                .LazyLoad()
                .AsBag();

            Cache.ReadWrite();
        }
    }
}
